import { BlackBoard } from "../../GameAPP/View/class/BlackBoard";
import { StateType } from "../../GameAPP/View/enum/StateType";
import { IState } from "../interface/IState";

/**
 * 状态机
 */
@ccclass('FSM')
export class FSM{
    public curState:IState;
    public states = new Map<StateType,IState>;
    public blackboard:BlackBoard;

    public constructor(blackboard:BlackBoard){
        this.states = new Map<StateType,IState>();
        this.blackboard = blackboard;
    }

    public AddState(stateType:StateType,state:IState){
        if(this.states.has(stateType)){
            return;
        }
        this.states.set(stateType,state);
    }

    public SwitchState(stateType:StateType){
        if(!this.states.has(stateType)){
            return;
        }
        if(this.curState != null){
            this.curState.OnExit();
        }
        this.curState = this.states.get(stateType);
        this.curState.OnEnter();
    }

    public GetIState(stateType:StateType){
        return this.states.get(stateType);
    }

    public OnUpdate(deltaTime){
        this.curState?.OnUpdate(deltaTime);
    }

    // public OnCheck(){
    //     this.curState.OnCheck();
    // }

    // public OnFixedUpdate(){
    //     this.curState.OnFixedUpdate();
    // }

}

function ccclass(arg0: string): (target: typeof FSM) => void | typeof FSM {
    throw new Error("Function not implemented.");
}

